<template>
	<jk-dialog
		v-model="showDialog"
		:title="`${dataItem.belongDate}-投料明细`"
		width="1000px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<jk-table ref="jkTable" :data="tableData" border :height="dialogTableHeight - 10" style="width: 100%">
			<vxe-table-column field="feedstockDateTime" title="时间" align="left" :width="160" fixed="left"></vxe-table-column>
			<vxe-table-column field="productName" title="品种" align="left" :min-width="160" fixed="left"></vxe-table-column>
			<vxe-table-column field="productModels" title="规格" align="left" :min-width="160"></vxe-table-column>
			<vxe-table-column field="totalWeight" title="投料重量" align="right" :min-width="100"></vxe-table-column>
			<vxe-table-column field="empList" title="投料人" align="right" :min-width="200">
				<template slot-scope="scope">
					<span>{{ scope.row.empList ? scope.row.empList.map(x => x.name).join() : '' }}</span>
				</template>
			</vxe-table-column>
		</jk-table>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { productionFeedstockPage } from '../../../api/production/feedMaterial';
    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataItem: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        mixins: [calHeight],
        data() {
            return {
                tableData: [],
                showDialog: false,
                showLoading: true
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                }
            },
            getListRequest() {
                if (this.dataItem.workshopId && this.dataItem.lineCode && this.dataItem.belongDate) {
                    this.showLoading = true;
                    return productionFeedstockPage({
                        billDate: [this.dataItem.belongDate, this.dataItem.belongDate],
                        productionLineCode: this.dataItem.lineCode,
                        pageSize: 1000,
                        workshopId: this.dataItem.workshopId,
                        auditState: 1
                    }).then(res => {
                        this.showLoading = false;
                        if (res.data.status === 200) {
                            this.tableData = res.data.res;
                        }
                    });
                }
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getListRequest();
                }
            }
        }
    };
</script>
